from django.shortcuts import render
from django.http import HttpResponse
from blog import models
# Create your views here.

info_list = []
def userInfor(req):
    if req.method == "POST":
        username = req.POST.get("username", None)
        sex = req.POST.get("sex", None)
        email = req.POST.get("email", None)
        info = {"username": username, "sex": sex, "email": email}

        #数据插入数据库
        models.User.objects.create(**info)
        info_list = models.User.objects.all()
        return render(req, "userInfor.html", {"info_list": info_list})
    return render(req, "userInfor.html")

def year(req,year,moth):
    return HttpResponse(year + "year" + moth + "moth")
def login(req):
    if req.method == "POST":
        username = req.POST.get("username")
        pwd = req.POST.get("password")
        print("blog", username)
        if username == "alex" and pwd == "123":
            return HttpResponse("登录成功")
    return render(req, "login.html")

def oder(req):
    return render(req, "oder.html")

def shoppingcar(req):
    return render(req, "shoppingcar.html")


def play(req):
    return HttpResponse("200")

